$().ready(function () {
    //uxiliaryTypeBind();
    listUxiliaryClass();
    validateRule();
});

$.validator.setDefaults({
    submitHandler: function () {
        save();
    }
});

function uxiliaryTypeBind() {
    $("#prodTypeId").html("");
    var str = "<option>==请选择===</option>";
    $.ajax({
        type: "GET",
        url: "/prod/uxiliaryInfo/listProdTypeId",
        // data: { "parentiD": "", "MyColums": "Province" },
        dataType: "JSON",
        async: false,
        success: function (data) {
            //从服务器获取数据进行绑定
            $.each(data, function (i, item) {
                str += "<option value=" + item.id + ">" + item.productName + "</option>";
            })
            //将数据添加到省份这个下拉框里面
            $("#prodTypeId").append(str);
        },
        error: function () {
            alert("Error");
        }
    });

}


function listUxiliaryClass() {
    $("#uxiliaryClass").html("");
    var str = "<option>==请选择===</option>";
    $.ajax({
        type: "GET",
        url: "/prod/uxiliaryInfo/listUxiliaryClass",
        // data: { "parentiD": "", "MyColums": "Province" },
        dataType: "JSON",
        async: false,
        success: function (data) {
            //从服务器获取数据进行绑定
            $.each(data, function (i, item) {
                str += "<option value=" + item.value + ">" + item.name + "</option>";
            })
            //将数据添加到省份这个下拉框里面
            $("#uxiliaryClass").append(str);
        },
        error: function () {
            alert("Error");
        }
    });

}

function save() {
    $.ajax({
        cache: true,
        type: "POST",
        url: "/prod/uxiliaryInfo/save",
        data: $('#signupForm').serialize(), // 你的formid
        async: false,
        error: function (request) {
            parent.layer.alert("网络超时");
        },
        success: function (data) {
            if (data.code == 0) {
                parent.layer.msg("操作成功");
                parent.reLoad();
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);

            } else {
                parent.layer.alert(data.msg)
            }
        }
    });
}

function validateRule() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#signupForm").validate({
        rules: {
            name: {
                required: true
            }
        },
        messages: {
            name: {
                required: icon + "请输入名字"
            }
        }
    })
}